<?php
/**
 * Created by PhpStorm.
 * User: xufei
 * Date: 2018/5/4
 * Time: 上午11:55
 */

class wxapi_ctl_category extends wxapi_response
{
    public $pagedata;

    public function __construct(&$app)
    {
        parent::__construct($app);
    }

    public function rootCategoryList()
    {
        $cat_id = 0;
        $objCat = app::get('b2c')->model('goods_cat');
        $catlist = $objCat->getList('*', array('parent_id' => $cat_id), $offset = 0, $limit = -1, 'p_order ASC');
        $rootCategoryArr = array();
        if (!empty($catlist)){
            foreach($catlist as $category)
            {
                $rootCategory = [];
                $rootCategory['code'] = $category['cat_id'];
                $rootCategory['name'] = $category['cat_name'];
                $rootCategory['logo'] = base_storager::image_path($category['spec_image']);
                $rootCategory['id']   = $category['cat_id'];
                $rootCategoryArr[] = $rootCategory;
            }
        }
        $return = [
            'reason'=>"",
            'code'=>0,
            'list' => $rootCategoryArr,
        ];

        self::return_json($return);
    }

    /**
     * 子级分类
     */
    public function childCategoryList(){
        //临时数据写死的
        $data =  $this->__tempCategory();
        self::return_json($data);
    }


    /**
     * 临时分类页数据
     */
    private function __tempCategory(){

        $navigator = app::get('wxapi')->getConf('wxapps.navigator');
        foreach ($navigator as $k=>$v) {
            $navigator[$k]['thumLogo'] = base_storager::image_path($v['thumLogo']);
            if($v['type'] == 'tag') {//只显示分类
                unset($navigator[$k]);
            }
        }
        //return $navigator;
        return array(
          'reason'=>'',
          'code'=>'0',
          'list'=>$navigator,
        );
    }

    /*新产品分类页接口*/
    public function getClassify()
    {
        //s1. 基础数据
        $baseData = app::get('wxapi')->getConf('wxapps.classify');
        $orange   = array();
        //s2. 首个栏目名称
        $orange['item_name'] = ($baseData['item_name']?:'精品专区');
        //s3. 二级栏目
        foreach ((array)$baseData['children'] as $v) {
            $v['thumLogo'] = base_storager::image_path($v['thumLogo']);
            $orange['children'][] = $v;
        }
        //s4. 一级栏目
        $tagMdl = app::get('desktop')->model('tag');
        //$catList = $catMdl->getList('cat_name,cat_id',array('disabled'=>'false'));
        foreach ((array)$baseData['stairlist'] as $v) {
            $rw = $tagMdl->getRow('tag_id,tag_name',array('tag_id'=>$v));
            $orange['stairlist'][] = $rw;
        }
        //s5. 输出结果处理
        $res = array(
            'reason'=>'',
            'code'=>'0',
            'data'=>$orange,
        );
        self::return_json($res);
    }

}